import 'package:flutter/material.dart';
import 'package:get/get.dart';

extension String2RouteExt on String {
  Future? pushNamed({dynamic arg}) {
    return Get.toNamed(this, arguments: arg);
  }

  Future? popAndPushNamed({dynamic arg}) {
    return Get.offAndToNamed(this, arguments: arg);
  }

  Future? pushNamedAndPopAll({dynamic arg}) {
    return Get.offAllNamed(this, arguments: arg);
  }

  void until() {
    Get.until((route) => Get.currentRoute == this);
  }

  Future? offNamedUntil(String until, {dynamic arg}) {
    return Get.offNamedUntil(this, ModalRoute.withName(until), arguments: arg);
  }
}

extension State2RouteExt on State {
  void pop<T extends Object?>([T? result]) {
    Navigator.pop(context, result);
  }
}
